﻿using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraRichEdit;
using NursingFormSystem.DNNursingService;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;

namespace NursingDocumentInfoSystem
{
    public partial class TemperatureIn : Form
    {
        public string sql = "";
        public string PID = "";
        public string VID = "";
        public string date ="";
        public string xueya = "";
        public string xueya1 = "";
        public string xueya2 = "";
        public string tiwen = "";
        public string huxi = "";
        public string xinlv = "";
        public string maibo = "";
        public BNNursingDocsSystem bnService = new BNNursingDocsSystem();
        public TemperatureIn(string PatientID,string visitID)
        {
            InitializeComponent();
            PID = PatientID;
            VID = visitID;
            //  sql = @"SELECT *  FROM [BNNursingDocsSystem_Develop].[dbo].[T_temperature](NOLOCK)  where PatientId = '"+PatientID+"' and VISIT_ID ='"+visitID+"'";
            dateTimePicker1.Text = System.DateTime.Now.ToShortDateString();
            date = Convert.ToDateTime(System.DateTime.Now.ToShortDateString()).ToString("yyyy-MM-dd");
            Creat();
           
            
        }
        void Creat()
        {
            date = Convert.ToDateTime(dateTimePicker1.Value).ToString("yyyy-MM-dd");
            DataTable temp = bnService.GetTemperature(PID, Convert.ToInt32(VID), date).D;
            temp.Columns.Add("勾选", System.Type.GetType("System.Boolean"));
            temp.Columns["勾选"].SetOrdinal(0);
            temp.Columns[1].Caption = "护理时间";
            temp.Columns[2].Caption = "血压";
            temp.Columns[3].Caption = "体温";
            temp.Columns[4].Caption = "呼吸";
            temp.Columns[5].Caption = "心率";
            temp.Columns[6].Caption = "脉搏";
            gridControl1.DataSource = temp;
            gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never;   //是否显示过滤面板
            gridView1.OptionsCustomization.AllowFilter = false;                      //是否允许过滤                     
            gridView1.OptionsSelection.MultiSelect = true;
            gridView1.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect;
            for (int i = 0; i < gridView1.Columns.Count; i++)
            {
                if (gridView1.Columns[i].Name != "col勾选")
                {
                    gridView1.Columns[i].OptionsColumn.AllowEdit = false;
                }
            }

            gridView1.OptionsCustomization.AllowSort = false;
           
            gridView1.OptionsView.ColumnAutoWidth = false;
            gridView1.Columns["勾选"].Width = 30;
            gridView1.Columns["勾选"].Caption = " ";
            gridView1.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            gridView1.Columns[1].Width = 100;
            gridView1.Columns[2].Width = 80;
            gridView1.Columns[3].Width = 80;
            gridView1.Columns[4].Width = 80;
            gridView1.Columns[5].Width = 80;
            gridView1.Columns[6].Width = 80;
           
            //  gridView1.OptionsBehavior.Editable = false;
            gridView1.Appearance.Row.TextOptions.HAlignment = HorzAlignment.Center;
            gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            Creat();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string value = "";
            int Checked = 0;
            for (int i = 0; i < gridView1.RowCount; i++)
            {
                value = gridView1.GetDataRow(i)["勾选"].ToString();
                if (value == "True")
                {
                    Checked++;
                }
            }
            if(Checked == 1)
            {
                DialogResult = DialogResult.Yes;
                for (int i = 0; i < gridView1.RowCount; i++)
                {
                    value = gridView1.GetDataRow(i)["勾选"].ToString();
                    if (value == "True")
                    {
                        tiwen = gridView1.GetDataRow(i)[3].ToString();
                        huxi = gridView1.GetDataRow(i)[4].ToString();
                        xinlv = gridView1.GetDataRow(i)[5].ToString();
                        maibo = gridView1.GetDataRow(i)[6].ToString();
                        xueya = gridView1.GetDataRow(i)[2].ToString();
                        if(xueya.Length > 0)
                        {
                            string[] temp = Regex.Split(xueya, "¤", RegexOptions.IgnoreCase);
                            xueya = temp[0];
                            string[] temp2 = Regex.Split(xueya, "/", RegexOptions.IgnoreCase);
                            if(temp2.Length == 2)
                            {
                                xueya1 = temp2[0];
                                xueya2 = temp2[1];
                            }                          
                        }
                        Close();
                    }
                }
            }
            else
            {
                XtraMessageBox.Show("只支持勾选1条记录时导入!");
            }
        }
    }
}
